<?php
// +---------------------------------------------------------------
// | Package: Tommy Framework
// +---------------------------------------------------------------
// | Version $Id: Widget.class.php 2010-3-30 12:30:30 $
// +---------------------------------------------------------------
// | Copyright (c) 2009 http://www.tommyframework.com All rights reserved.
// +---------------------------------------------------------------
// | Author: tommy <service@tommyframework.com>
// +---------------------------------------------------------------

if(!defined('IN_TOMMY')){
	exit;
}
abstract class Widget extends Controller{
	//提交函数.
	public function render($widget_name){
		if(empty($widget_name)){
			return false;
		}
		static $_instance = array();
		$widget_name = ucfirst(strtolower($widget_name)).'Widget';
		if(!isset($_instance[$widget_name])){
			$_instance[$widget_name] = new $widget_name();
		}
		$_instance[$widget_name]->render();
	}
	//重载cache函数,防止cache函数与controller中的cache相冲突.
	public function cache(){
		return true;
	}
	public function set_cache(){
		return false;
	}
	//模板输出.
	public function display($file_name=false){
		if(empty($file_name))
			$file_name = strtolower(substr(get_class($this),0, -6));
		return self::$view->widget($file_name);
	}
}
?>